package com.video.main_video.api;

import com.video.main_video.manager.apiConfig.collections.CollectionsEnumApi;
import com.video.main_video.manager.apiConfig.comment.CommentEnumApi;
import com.video.main_video.manager.apiConfig.userInfo.UserInfoEnumApi;
import com.video.main_video.manager.apiConfig.videoUpdate.VideoUpdateEnumApi;

import java.util.Objects;

public enum ServiceEnumApi {
    VIDEOUPDATE(VideoUpdateEnumApi.class,"VIDEOUPDATE",1),
    USERVIDEOINFO(UserInfoEnumApi.class,"USERVIDEOINFO",2),
    COMMENT(CommentEnumApi.class,"COMMENT",3),
    COLLECTION(CollectionsEnumApi.class,"COLLECTION",5),
    ;

    Class name;

    String desc;

    Integer code;

    private ServiceEnumApi(Class name, String desc,Integer code) {
        this.name = name;
        this.desc = desc;
        this.code=code;
    }


    // 通过code获取名称
    public static Class formName(int code) {
        for (ServiceEnumApi c : ServiceEnumApi.values()) {
            if (c.getCode() == code) {
                return c.name;
            }
        }
        return null;
    }

    // 通过code获取名称
    public static Class fromNameByDesc(String desc) {
        for (ServiceEnumApi c : ServiceEnumApi.values()) {
            if (Objects.equals(c.getDesc(), desc)) {
                return c.name;
            }
        }
        return null;
    }
    // 通过名称获取code
    public static Integer formCode(Class name) {
        for (ServiceEnumApi c : ServiceEnumApi.values()) {
            if (Objects.equals(c.getName(), name)) {
                return c.code;
            }
        }
        return null;
    }

    public Class getName() {
        return name;
    }

    public void setName(Class name) {
        this.name = name;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }
}
